<?php

namespace App\Models\User;

use App\Models\Address\Address;
use App\Models\BaseModel;

/**
 * 用户模型层
 *
 * Class Role
 * @package App\Models\User
 */
class User extends BaseModel
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'user';

    /**
     * Indicates if the model should be timestamped.
     * @var bool
     */
    public $timestamps = false;

    protected $guarded = [];

//    public $appends = ['sex_text'];
//    public $casts = ['other_info' => 'array'];

    public $sexText = ['gent' => '男', 'lady' => '女', 'no' => '保密'];

    public function getSexAttribute($value)
    {
        return $this->sexText[$value];
    }

    public function provinceText()
    {
        return $this->hasOne(Address::class, 'id', 'province');
    }

    public function cityText()
    {
        return $this->hasOne(Address::class, 'id', 'city');
    }

    public function countyText()
    {
        return $this->hasOne(Address::class, 'id', 'county');
    }

    public function car(){
        return $this->hasOne('App\Models\Car\Car','user_id','id');
    }

}
